package org.example.current.provider.rest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jie.luo
 * @description
 * @since 2020-06-16
 */
@RestController
@RefreshScope
public class ProviderRest {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @GetMapping("/hello")
    public String hello() {
        return "hello nacos provider";
    }

    @Value("${current.env}")
    private String currentEnv;

    @GetMapping("/config")
    public String config() {
        return currentEnv;
    }

    @GetMapping("/user")
    public String getUserName(@RequestParam(name = "userId") Integer id) {

        try {
            for (int i = 0; i < id; i++) {
                Thread.sleep(1000);
                logger.debug("休眠中....." + i);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return "username is openfeign";
    }

    @GetMapping("/users")
    public String getUsers() {
        logger.debug("---------------------users---------------------");
        return "this is get users";
    }
}
